import {
  UserListBySearchParams,
  RolePageParams,
  RoleListItem,
  UserListGetResultModel,
  UserDeptInfo,
  UserRoleInfo,
  DeptListBySearchParams,
  DeptListGetResultModel,
  RolePageListGetResultModel,
  PermissionInfo,
  DeptListItem,
  SecurityLogsListBySearchParams,
  SecurityLogsListGetResultModel,
  MenuListItem,
  MenuListBySearchParams,
  RoleNaviationListItem,
  LanguageItem,
} from './model/systemModel';
import { defHttp } from '/@/utils/http/axios';

enum Api {
  AccountList = '/system/getAccountList',
  IsAccountExist = '/system/accountExist',

  setRoleStatus = '/system/setRoleStatus',
  Menu = '/app/navigations',
  RolePageList = '/system/getRoleListByPage',
  GetAllRoleList = '/system/getAllRoleList',

  Dept = '/app/organization-units',
  Role = '/identity/roles/',
  Permission = '/permission-management/permissions',
  Users = '/identity/users',
  Users_Ext = '/app/user-exten/',
  Security_Logs = '/app/security-logs',
  AuditLogs_Logs = '/app/audit-logs',
  Role_Navigation = '/app/role-navigations',
  Application_Configure = '/abp/application-configuration',
}
//用户信息
export const getUsersList = (params: UserListBySearchParams) =>
  defHttp.get<UserListGetResultModel>({ url: Api.Users_Ext + 'users', params });

export const postUsers = (params: any) => defHttp.post({ url: Api.Users, params });

export const putUsers = (id: string, params: any) =>
  defHttp.put({ url: Api.Users + '/' + id, params });

export const getUsersDepts = (uid: string) =>
  defHttp.get<UserDeptInfo>({ url: Api.Users_Ext + 'depts-by-uid', params: { uid } });

export const getUsersRoleList = (id: string) =>
  defHttp.get<UserRoleInfo[]>({ url: Api.Users + '/' + id + '/roles' });

//部门接口
export const getDeptAllList = () => defHttp.get<DeptListItem[]>({ url: Api.Dept + '/list' });
export const getDeptList = (params?: DeptListBySearchParams) =>
  defHttp.get<DeptListGetResultModel>({ url: Api.Dept, params });
export const postDept = (DisplayName: string, ParentId?: string) =>
  defHttp.post({ url: Api.Dept, params: { DisplayName, ParentId } });
export const putDept = (id: string, data: any) => defHttp.put({ url: Api.Dept + '/' + id, data });
//角色
export const getRoleAllList = () => defHttp.get<RoleListItem[]>({ url: Api.Role + 'all' });
export const getRoleList = (params: RolePageParams) =>
  defHttp.get<RolePageListGetResultModel>({ url: Api.Role, params });
export const postRole = (data: any) => defHttp.post({ url: Api.Role, data });
export const putRole = (id: string, data: any) => defHttp.put({ url: Api.Role + id, data });
//权限
export const getPermissionList = (providerName: string, providerKey: string) =>
  defHttp.get<PermissionInfo>({
    url: Api.Permission,
    params: { providerName, providerKey },
  });
export const putPermission = (providerName: string, providerKey: string, data: any) =>
  defHttp.put(
    {
      url: Api.Permission + '?providerName=' + providerName + '&providerKey=' + providerKey,
      data,
    },
    { isTransformResponse: false },
  );
//更新密码
export const putPwd = (data: any) =>
  defHttp.put({
    url: Api.Users_Ext + 'users-pwd',
    data,
  });
//登录日志
export const getSecurityLogs = (params: SecurityLogsListBySearchParams) =>
  defHttp.get<SecurityLogsListGetResultModel>({ url: Api.Security_Logs, params });
//业务日志
export const getAuditLogs = (params: SecurityLogsListBySearchParams) =>
  defHttp.get<SecurityLogsListGetResultModel>({ url: Api.AuditLogs_Logs, params });
//菜单
export const getMenuList = (params?: MenuListBySearchParams) =>
  defHttp.get<MenuListItem[]>({ url: Api.Menu, params });
export const postMenu = (data: any) => defHttp.post({ url: Api.Menu, data });
export const putMenu = (id: string, data: any) =>
  defHttp.put({ url: Api.Menu + '/' + id, data }, { isTransformResponse: false });
//角色菜单
export const getRoleNavigationList = (params: any) =>
  defHttp.get<RoleNaviationListItem[]>({ url: Api.Role_Navigation, params });
export const putRoleNavigation = (id: string, data) =>
  defHttp.put({ url: Api.Role_Navigation + '/' + id, data }, { isTransformResponse: false });
//语言
export const getLanguages = () => defHttp.get<LanguageItem[]>({ url: Api.Application_Configure });
